package com.fantasy.gethtml2excel;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.fantasy.excel.WriteExcel;
import com.fantasy.httpclient.TestLogin;

public class Html2Excel {
	
	private static List<ArrayList<String>> dataList = new ArrayList<ArrayList<String>>(1200);
	
	public static void getHtml2List(){
		for(int i=1 ; i < 66 ; i++){
			try {
				System.out.println("第" + i + "页");
				String sb = TestLogin.getHtml(i).toString();
				Document doc = Jsoup.parse(sb);
				Elements newsHeadlines = doc.select("tr[onmouseover=\"this.bgColor = '#C2E9FC'\"]");
				for(Element elem : newsHeadlines){
					ArrayList<String> elementList = new ArrayList<String>(8);
					elementList.add(elem.select("td:eq(1)").html());
					elementList.add(elem.select("td:eq(2) a").html());
					elementList.add(elem.select("td:eq(3) a").html());
					elementList.add(elem.select("td:eq(4)").html());
					elementList.add(elem.select("td:eq(5)").html());
					elementList.add(elem.select("td:eq(6)").html());
					elementList.add(elem.select("td:eq(7)").html());
					elementList.add(elem.select("td:eq(8)").html());
					//System.out.println(elem.select("td:eq(2) a").html());
					dataList.add(elementList);
				}
				
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	
	public static void main(String[] args) {
		getHtml2List();
		WriteExcel.writeToExcel(dataList , "d://bomList");
	}
	
}